<template>
	<div class="index__partBox__src-partition-secondZone-" :class="{op:ISa}">
			<div class="index__pagesContainer__src-partition-secondZone-">
				<div class="index__scrollContainer__src-partition-secondZone-">
					<router-link class="index__tab__src-partition-secondZone-tab-" :to="{name:'channel',params:{tid:curtid}}">
						<p>推荐</p>
					</router-link>
					<router-link :to="{name:'channel',params:{tid:item.tid}}" v-for="(item,index) in secondList" :key="index" class="index__tab__src-partition-secondZone-tab-">
						<p>{{item.typename}}</p>
					</router-link>
				</div>
			</div>
		</div>
</template>

<script>
let partitionList=window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
export default{
	name:'fnav3',
	props:{
		tid:{
			type:[String,Number],
			default:"1"
		}
	},
	watch:{
		$route(newValue){
			this.$emit("Pchangetid",newValue.params.tid)
		},
		tid(newValue){
			//实时更新newList的内容
//			this.newList=partitionList[this.tid]
			console.log(this.$store.getters.getcurtid)
			this.secondList=partitionList[this.$store.getters.getcurtid]
			console.log(this.secondList)
			this.curtid=this.$store.getters.getcurtid
		}
	},
	data(){
		return{
			newList:[],
			curtid:"1",
			ISa:false
		}
	},
	created(){
		this.$store.commit("setcurtid",{
			curtid:this.$route.params.tid
		})
		this.curtid=this.$store.getters.getcurtid
//		this.newList=partitionList[this.tid]
//		this._SetsecondList(this.$route.params.tid)
	},
	computed:{
		secondList:{
			get:function(){
				this.curtid=this.$store.getters.getcurtid
				this.newList=partitionList[this.curtid]
				return this.newList
			},
			set:function(newValue){
//				if(newValue){
////					this.curtid=this.tid
//					this.curtid=this.$store.getters.getcurtid
//				}
//				this.newList=partitionList[this.curtid]
			}
		}
	},
	methods:{
//		_SetsecondList(tid){
//			const hasCon=partitionList[this.tid]
//			console.log(hasCon)
//			if(!hasCon){
//				//遍历大对象的属性名(键名)
//				let handleNav=function(){
//					const keyArr=Object.keys(partitionList)
////					console.log(keyArr)
//	//				核心代码:找tid==obj.tid
//					for(let i=0,len=keyArr.length;i<len;i++){
//	//					一定要清楚,你访问的元素是什么
//						const tmpArr=partitionList[keyArr[i]]
//						for(let j=0;j<tmpArr.length;j++){
//	//						内循环
////							console.log(tmpArr)
//	//						核心代码
//							if(tmpArr[j].tid==tid){
//								return keyArr[i]
//							}
//						}
//					}
//				}
//				this.curtid=handleNav()
//			}else{
//				this.curtid=tid
//			}
////			this.$store.commit('setcurtid',this.curtid)
//			this.newList=partitionList[this.curtid]
//		}
		scrollEvent(){
				let self = this;
				let scrollDirection;
				let scrollAction = {x: 'undefined', y: 'undefined'};
				window.addEventListener("scroll",(e)=>{
					let doc = window.pageYOffset;
				    if (typeof scrollAction.x == 'undefined') {
				        scrollAction.x = window.pageXOffset;
				        scrollAction.y = window.pageYOffset;
				    }
				    var diffX = scrollAction.x - window.pageXOffset;
				    var diffY = scrollAction.y - window.pageYOffset;
				    if (diffX < 0) {
				        // Scroll right
				        scrollDirection = 'right';
				    } else if (diffX > 0) {
				        // Scroll left
				        scrollDirection = 'left';
				    } else if (diffY < 0) {
				        // Scroll down
				        scrollDirection = 'down';
				    } else if (diffY > 0) {
				        // Scroll up
				        scrollDirection = 'up';
				    } else {
				        // First scroll event
				    }
				    scrollAction.x = window.pageXOffset;
				    scrollAction.y = window.pageYOffset;
			        if(scrollDirection == 'down'){
			            //页面向下滚动要做的事情
			            if(doc>=30){
//							console.log(doc)
			            	self.ISa=true
			            }
			            
			        }
			        else if(scrollDirection == 'up'){
		            	self.ISa=false
			        }
			    })
			},
	},
	mounted(){
		this.scrollEvent()
	}
}
</script>

<style lang="scss">
	.op{
	    transform: translateY(-100%);
	}
</style>